const tokenModule = require('../module/tool/token');
const authConfig = require('../../config/auth.json');

/**
 * @Description 生成小程序端Token
 * @author hacket
 * @date 2021/2/25 00:21
 */
async function generateMiniProgramToken (tokenData, expire = authConfig.MiniProgram.JWT.expire) {
    return tokenModule.generateToken(tokenData, authConfig.MiniProgram.JWT.privateKey, expire);
}

/**
 * @Description 生成后台Token
 * @author hacket
 * @date 2021/2/25 00:20
 */
async function generateAdminSiteToken (tokenData, expire = authConfig.AdminSite.JWT.expire) {
    return tokenModule.generateToken(tokenData, authConfig.AdminSite.JWT.privateKey, expire);
}

/**
 * @Description 解析小程序端Token
 * @param {String} token 授权TOKEN
 * @author 53010
 * @date 2020/6/5 17:54
 */
async function parseMiniProgramToken (token) {
    return tokenModule.parseToken(token, authConfig.MiniProgram.JWT.privateKey);
}

/**
 * @Description 解析后台Token
 * @author hacket
 * @date 2021/2/25 00:16
 */
async function parseAdminSiteToken (token) {
    return tokenModule.parseToken(token, authConfig.AdminSite.JWT.privateKey);
}

module.exports = {
    generateAdminSiteToken,
    parseMiniProgramToken,
    parseAdminSiteToken,
    generateMiniProgramToken
};
